<?php
/**
 * add a new rail object to current inventory.
 *
 * PHP versions 5
 *
 * Copyright (C)
 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
 * of ERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software
 * Fundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
 *
 * @author Bastian Schröder <bs@chemanet.de>
 * @version 2007-08-02
 * @package rail
 */

session_start();

require_once( 'railbrowser.conf.php' );
require_once( $cfg_pahToPHPrail . '/rail_connector.class.php' );
require_once( 'includes/derive_icon.php' );

$rail = new rail_connector( $cfg_mysql_db, $cfg_mysql_user, $cfg_mysql_passwd, $cfg_mysql_host );
$rail->login($cfg_rail_user, $cfg_rail_passwd);

$object = rail_factory::get_object( $rail, $_SESSION['last_path'] );


/* ------------------------------------ Listener -------------------------------------- */
// add object
if( isset( $_POST['a_name'] ) && strlen( trim( $_POST['a_name'] ) ) > 0 ){
	switch( $_POST['rail_type'] ){
		case 'rail_object':
			rail_factory::create_object( $rail, $object, $_POST['a_name'] );
			break;
		case 'rail_user':
			rail_factory::create_user( $rail, $object, $_POST['a_name'], uniqid($_POST['a_name']) );
			break;
		case 'rail_group':
			rail_factory::create_group( $rail, $object, $_POST['a_name'] );
			break;
		case 'rail_container':
			rail_factory::create_container( $rail, $object, $_POST['a_name'], uniqid($_POST['a_name']) );
			break;
		case 'rail_page':
			rail_factory::create_page( $rail, $object, $_POST['a_name'] );
			break;
		case 'rail_document':
			rail_factory::create_document( $rail, $object, $_POST['a_name'] );
			break;
	}
	echo "<script type=\"text/javascript\">parent.location.reload();</script>";
}


/* -------------------------------------- Display ------------------------------------- */
$smarty = new rail_smarty();
$smarty->caching = false;
$smarty->display( 'addobject.tpl' );

?>